//
//  firstViewController.m
//  mintHome
//
//  Created by 朱彦名 on 16/7/5.
//  Copyright © 2016年 朱彦名. All rights reserved.
//

#import "firstViewController.h"
#import "AppDelegate.h"


@interface firstViewController ()<UIScrollViewDelegate>
@property (nonatomic, retain) NSArray *arrForImage;
@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, assign) BOOL isOut;

@end

@implementation firstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    /** arrForImage */
    
    self.arrForImage = @[@"woshi.jpg", @"keting.jpg", @"chufang1.jpg", @"weiyu.jpg"];
    
    /** scrollView */
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    
    self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * _arrForImage.count, self.view.frame.size.height);
    
    self.scrollView.pagingEnabled = YES;
    
    self.scrollView.delegate = self;
    
    
    
    [self.view addSubview:self.scrollView];
    
    for (int i = 0 ; i < 4; i++) {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imageView.image = [UIImage imageNamed:_arrForImage[i]];
        
        [self.scrollView addSubview:imageView];
        
    }
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.contentOffset.x > 2 * self.view.frame.size.width) {
        _isOut = YES;
    }

}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    AppDelegate *app = [[UIApplication sharedApplication] delegate];
    
    if (_isOut) {
        [UIView animateWithDuration:1.5 animations:^{
            scrollView.alpha = 0;
        } completion:^(BOOL finished) {
            [scrollView removeFromSuperview];
#pragma mark - 修改window的根视图
            app.window.rootViewController = app.tabBar;
            [self presentViewController:app.tabBar animated:YES completion:^{
                
            }];
        }];
    }
}

@end
